﻿<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>教务管理系统 - 作业提交情况</title>
    <link href="${pageContext.request.contextPath}/resources/bootstrap5/css/bootstrap.min.css" rel="stylesheet">
    <!-- Bootstrap Icons - 本地版本 -->
    <link href="${pageContext.request.contextPath}/resources/bootstrap-icons/1.11.3/bootstrap-icons.css" rel="stylesheet">
    <!-- Bootstrap Icons - 备用CDN -->
    <link href="https://cdn.bootcdn.net/ajax/libs/bootstrap-icons/1.11.3/font/bootstrap-icons.min.css" rel="stylesheet">
    <!-- 第二个备用CDN -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css">
    <style>
        body {
            font-family: "Microsoft YaHei", sans-serif;
            background-color: #f5f5f5;
            margin: 0;
            padding: 0;
        }

        .header {
            background-color: #1976d2;
            color: white;
            padding: 10px 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            position: fixed;
            width: 100%;
            top: 0;
            z-index: 1000;
        }

        .header-left {
            display: flex;
            align-items: center;
            gap: 20px;
        }

        .header h2 {
            margin: 0;
            font-size: 1.5rem;
            display: flex;
            align-items: center;
        }

        .header h2 img {
            height: 36px;
            margin-right: 10px;
        }

        .header .breadcrumb {
            margin: 0;
            background: transparent;
            color: white;
        }

        .header .breadcrumb a {
            color: rgba(255,255,255,0.8);
            text-decoration: none;
        }

        .header .breadcrumb a:hover {
            color: white;
        }

        .header .breadcrumb-item.active {
            color: white;
        }

        .header .breadcrumb-item+.breadcrumb-item::before {
            color: rgba(255,255,255,0.6);
        }

        /* 侧边栏样式 */
        .sidebar {
            position: fixed;
            top: 56px;
            left: 0;
            bottom: 0;
            width: 250px;
            background-color: white;
            box-shadow: 2px 0 5px rgba(0,0,0,0.1);
            overflow-y: auto;
            z-index: 100;
            padding-top: 20px;
        }

        .sidebar-menu {
            list-style: none;
            padding: 0;
            margin: 0;
        }

        .sidebar-menu > li {
            margin-bottom: 5px;
        }

        .sidebar-menu > li > a {
            display: flex;
            align-items: center;
            padding: 12px 20px;
            color: #333;
            text-decoration: none;
            transition: all 0.3s;
            border-left: 3px solid transparent;
        }

        .sidebar-menu > li > a:hover {
            background-color: #f0f0f0;
            border-left-color: #1976d2;
        }

        .sidebar-menu > li > a.active {
            background-color: #e3f2fd;
            border-left-color: #1976d2;
            color: #1976d2;
        }

        .sidebar-menu > li > a i {
            margin-right: 10px;
            width: 20px;
            text-align: center;
            font-size: 1.1rem;
        }

        .sidebar-submenu {
            list-style: none;
            padding-left: 53px;
            max-height: 0;
            overflow: hidden;
            transition: max-height 0.3s ease;
        }

        .sidebar-menu > li.open .sidebar-submenu {
            max-height: 500px;
        }

        .sidebar-submenu > li > a {
            display: block;
            padding: 8px 0;
            color: #666;
            text-decoration: none;
            transition: all 0.3s;
        }

        .sidebar-submenu > li > a:hover {
            color: #1976d2;
        }

        .sidebar-submenu > li > a.active {
            color: #1976d2;
            font-weight: 500;
        }

        /* 内容区样式 */
        .content {
            margin-left: 250px;
            padding: 76px 20px 20px;
        }

        /* 用户名下拉菜单样式 */
        .header-user {
            display: flex;
            align-items: center;
            position: relative;
        }
        .header-user-avatar {
            width: 32px;
            height: 32px;
            border-radius: 50%;
            margin-right: 8px;
            object-fit: cover;
            background: #fff;
            cursor: pointer;
            transition: transform 0.2s;
        }
        .header-user-avatar:hover {
            transform: scale(1.1);
        }
        .header-user-name {
            font-size: 1rem;
            font-weight: 500;
            cursor: pointer;
            font-family: 'Microsoft YaHei', Arial, sans-serif;
        }
        .user-dropdown {
            position: absolute;
            top: 100%;
            right: 0;
            background: #fff;
            border-radius: 8px;
            box-shadow: 0 4px 12px rgba(0,0,0,0.15);
            min-width: 160px;
            z-index: 1001;
            opacity: 0;
            visibility: hidden;
            transform: translateY(-10px);
            transition: all 0.3s ease;
            margin-top: 8px;
        }
        .user-dropdown.show {
            opacity: 1;
            visibility: visible;
            transform: translateY(0);
        }
        .user-dropdown::before {
            content: '';
            position: absolute;
            top: -6px;
            right: 20px;
            width: 12px;
            height: 12px;
            background: #fff;
            transform: rotate(45deg);
            box-shadow: -2px -2px 4px rgba(0,0,0,0.1);
        }
        .user-dropdown-item {
            display: flex;
            align-items: center;
            padding: 12px 16px;
            color: #333;
            text-decoration: none;
            transition: background 0.2s;
            border-bottom: 1px solid #f0f0f0;
            font-family: 'Microsoft YaHei', Arial, sans-serif;
        }
        .user-dropdown-item:last-child {
            border-bottom: none;
        }
        .user-dropdown-item:hover {
            background: #f8f9fa;
            color: #1976d2;
        }
        .user-dropdown-item i {
            margin-right: 8px;
            width: 16px;
            text-align: center;
        }

        .card {
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.05);
            margin-bottom: 20px;
            overflow: hidden;
        }

        .card-header {
            padding: 15px 20px;
            background-color: white;
            border-bottom: 1px solid #eee;
            font-weight: 600;
            display: flex;
            justify-content: space-between;
            align-items: center;
            color: #333;
        }

        .card-body {
            padding: 20px;
        }

        .search-bar {
            display: flex;
            align-items: center;
            gap: 12px;
            margin-bottom: 18px;
            flex-wrap: nowrap;
        }

        .search-bar input, .search-bar select {
            border-radius: 8px;
            border: 1px solid #e3e3e3;
            padding: 6px 14px;
            font-size: 1rem;
            flex: 1;
            min-width: 150px;
        }

        .search-bar .btn {
            border-radius: 8px;
            font-size: 1rem;
            padding: 6px 18px;
            font-weight: 500;
            box-shadow: none;
            flex-shrink: 0;
        }

        .btn-primary {
            background: #1976d2;
            border: none;
        }

        .btn-primary:hover {
            background: #1565c0;
        }

        .btn-warning {
            background: #ffb300;
            color: #fff;
            border: none;
        }

        .btn-warning:hover {
            background: #ff9800;
            color: #fff;
        }

        .table {
            background: #fff;
            border-radius: 8px;
            overflow: hidden;
            box-shadow: 0 2px 8px rgba(0,0,0,0.04);
            margin-bottom: 0;
        }

        .table th {
            background: #f8f9fa;
            color: #1976d2;
            font-weight: 600;
            text-align: center;
            border-bottom: 2px solid #e3e3e3;
            border-top: none;
            padding: 12px;
        }

        .table tbody tr {
            transition: background 0.2s;
        }

        .table tbody tr:hover {
            background: #f1f8ff;
        }

        .table td, .table th {
            vertical-align: middle !important;
            text-align: center;
            border-color: #e9ecef;
        }

        .pagination {
            justify-content: center;
            margin-top: 12px;
        }

        .pagination .page-item .page-link {
            border-radius: 6px !important;
            margin: 0 2px;
            color: #1976d2;
            border: none;
            background: #fff;
            font-weight: 500;
            transition: background 0.2s, color 0.2s;
        }

        .pagination .page-item.active .page-link {
            background: #1976d2;
            color: #fff;
        }

        .pagination .page-item .page-link:hover {
            background: #e3f2fd;
            color: #1565c0;
        }

        @media (max-width: 768px) {
            .sidebar {
                transform: translateX(-100%);
                transition: transform 0.3s;
            }

            .sidebar.active {
                transform: translateX(0);
            }

            .content {
                margin-left: 0;
            }

            .search-bar {
                flex-wrap: wrap;
            }

            .search-bar input, .search-bar select {
                min-width: 100%;
                margin-bottom: 10px;
            }
        }
    </style>
</head>
<body>
<!-- 顶部导航栏 -->
<div class="header">
    <div class="header-left">
        <h2><img src="${pageContext.request.contextPath}/resources/images/logo.png" alt="Logo"> 教务管理系统</h2>
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="${pageContext.request.contextPath}/teacher/home">教师首页</a></li>
                <li class="breadcrumb-item active">作业提交情况</li>
            </ol>
        </nav>
    </div>

    <!-- 用户名下拉菜单 -->
    <div class="header-user" id="userDropdownContainer">
        <img src="${pageContext.request.contextPath}/resources/images/baimao.png" class="header-user-avatar" alt="用户名头像" id="userAvatar">
        <span class="header-user-name" id="userName">
                <c:choose>
                    <c:when test="${not empty currentTeacher and not empty currentTeacher.user and not empty currentTeacher.user.realName}">
                        ${currentTeacher.user.realName}
                    </c:when>
                    <c:when test="${not empty sessionScope.loggedInUser and not empty sessionScope.loggedInUser.realName}">
                        ${sessionScope.loggedInUser.realName}
                    </c:when>
                    <c:when test="${not empty sessionScope.loggedInUser and not empty sessionScope.loggedInUser.username}">
                        ${sessionScope.loggedInUser.username}
                    </c:when>
                    <c:otherwise>
                        教学管理员
                    </c:otherwise>
                </c:choose>
            </span>
        <div class="user-dropdown" id="userDropdown">
            <a href="#" class="user-dropdown-item" onclick="showProfileModal()">
                <i class="bi bi-person-circle"></i>
                查看个人信息
            </a>
            <a href="${pageContext.request.contextPath}/teacher/changePassword" class="user-dropdown-item">
                <i class="bi bi-key"></i>
                修改密码
            </a>
            <a href="${pageContext.request.contextPath}/user/logout" class="user-dropdown-item">
                <i class="bi bi-box-arrow-right"></i>
                退出登录
            </a>
        </div>
    </div>
</div>

<!-- 侧边栏 -->
<div class="sidebar">
    <ul class="sidebar-menu">
        <li>
            <a href="${pageContext.request.contextPath}/teacher/home">
                <i class="bi bi-house-door"></i> 教师首页
            </a>
        </li>
        <li>
            <a href="#" class="has-submenu">
                <i class="bi bi-megaphone"></i> 通知管理
            </a>
            <ul class="sidebar-submenu">
                <li><a href="${pageContext.request.contextPath}/teacher/notifications/academic">教学通知</a></li>
                <li><a href="${pageContext.request.contextPath}/teacher/notifications/exam">考试安排</a></li>
                <li><a href="${pageContext.request.contextPath}/teacher/notifications/classroom">教学资源安排</a></li>
            </ul>
        </li>
        <li class="open">
            <a href="#" class="has-submenu">
                <i class="bi bi-book"></i> 教学管理
            </a>
            <ul class="sidebar-submenu">
                <li><a href="${pageContext.request.contextPath}/teacher/courses">我的课程</a></li>
                <li><a href="${pageContext.request.contextPath}/teacher/course-students">选课学生</a></li>
                <li><a href="${pageContext.request.contextPath}/teacher/homework" class="active">作业管理</a></li>
                <li><a href="${pageContext.request.contextPath}/teacher/grades">成绩管理</a></li>
                <li><a href="${pageContext.request.contextPath}/teacher/attendance">考勤管理</a></li>
            </ul>
        </li>
        <li>
            <a href="#" class="has-submenu">
                <i class="bi bi-person-check"></i> 学生管理
            </a>
            <ul class="sidebar-submenu">
                <li><a href="${pageContext.request.contextPath}/teacher/evaluation">教学评价</a></li>
                <li><a href="${pageContext.request.contextPath}/teacher/leave">请假申请</a></li>
            </ul>
        </li>
        <li>
            <a href="${pageContext.request.contextPath}/user/logout">
                <i class="bi bi-box-arrow-right"></i> 退出登录
            </a>
        </li>
    </ul>
</div>

<!-- 内容区 -->
<div class="content">
    <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
        <h1 class="h2">作业提交情况</h1>
    </div>

    <c:if test="${not empty error}">
        <div class="alert alert-danger" role="alert">
                ${error}
        </div>
    </c:if>

    <!-- 作业信息 -->
    <div class="card">
        <div class="card-header">
            作业信息
        </div>
        <div class="card-body">
            <c:if test="${not empty homework}">
                <div class="row">
                    <div class="col-md-6">
                        <strong>作业标题：</strong>${homework.title}
                    </div>
                    <div class="col-md-6">
                        <strong>发布时间：</strong>
                        <c:choose>
                            <c:when test="${not empty homework.createTimeStr}">
                                ${homework.createTimeStr}
                            </c:when>
                            <c:otherwise>
                                <span class="text-muted">暂无发布时间</span>
                            </c:otherwise>
                        </c:choose>
                    </div>
                </div>
                <div class="row mt-2">
                    <div class="col-md-6">
                        <strong>截止日期：</strong>
                        <c:choose>
                            <c:when test="${not empty homework.deadlineStr}">
                                ${homework.deadlineStr}
                            </c:when>
                            <c:otherwise>
                                <span class="text-muted">暂无截止日期</span>
                            </c:otherwise>
                        </c:choose>
                    </div>
                    <div class="col-md-6">
                        <strong>提交人数：</strong>
                        <c:choose>
                            <c:when test="${not empty submissions}">
                                共 ${fn:length(submissions)} 人提交
                            </c:when>
                            <c:otherwise>
                                暂无提交
                            </c:otherwise>
                        </c:choose>
                    </div>
                </div>
                <div class="row mt-2">
                    <div class="col-md-6">
                        <strong>作业内容：</strong>
                        <c:choose>
                            <c:when test="${not empty homework.content}">
                                <div style="max-height: 100px; overflow-y: auto;">
                                        ${homework.content}
                                </div>
                            </c:when>
                            <c:otherwise>
                                <span class="text-muted">暂无作业内容</span>
                            </c:otherwise>
                        </c:choose>
                    </div>
                    <div class="col-md-6">
                        <strong>课程名称：</strong>
                        <c:choose>
                            <c:when test="${not empty homework.course.name}">
                                ${homework.course.name}
                            </c:when>
                            <c:otherwise>
                                <span class="text-muted">暂无课程名称</span>
                            </c:otherwise>
                        </c:choose>
                    </div>
                </div>
            </c:if>
        </div>
    </div>

    <!-- 查询表单 -->
    <div class="card">
        <div class="card-header">
            查询提交情况
        </div>
        <div class="card-body">
            <form method="get" action="${pageContext.request.contextPath}/teacher/homework/submissions/${homework.id}">
                <div class="search-bar">
                    <select name="status" class="form-select">
                        <option value="">全部状态</option>
                        <option value="submitted" ${param.status == 'submitted' ? 'selected' : ''}>已提交</option>
                        <option value="not_submitted" ${param.status == 'not_submitted' ? 'selected' : ''}>未提交</option>
                    </select>
                    <input type="text" class="form-control" name="studentName" value="${param.studentName}" placeholder="学生姓名">
                    <button type="submit" class="btn btn-primary">
                        <i class="bi bi-search"></i> 查询
                    </button>
                    <a href="${pageContext.request.contextPath}/teacher/homework/submissions/${homework.id}" class="btn btn-warning">
                        <i class="bi bi-arrow-clockwise"></i> 重置
                    </a>
                </div>
            </form>
        </div>
    </div>

    <!-- 提交情况列表 -->
    <div class="card">
        <div class="card-header">
            提交情况列表
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-hover">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>学号</th>
                        <th>姓名</th>
                        <th>提交时间</th>
                        <th>提交内容</th>
                        <th>成绩</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:choose>
                        <c:when test="${empty submissions}">
                            <tr>
                                <td colspan="8" class="text-center">暂无提交记录</td>
                            </tr>
                        </c:when>
                        <c:otherwise>
                            <c:forEach var="submission" items="${submissions}" varStatus="status">
                                <tr>
                                    <td>${status.count + (currentPage - 1) * pageSize}</td>
                                    <td>${submission.student.user.username}</td>
                                    <td>${submission.student.user.realName}</td>
                                    <td>
                                        <c:choose>
                                            <c:when test="${not empty submission.createTimeStr}">
                                                ${submission.createTimeStr}
                                            </c:when>
                                            <c:otherwise>
                                                <span class="text-muted">暂无提交</span>
                                            </c:otherwise>
                                        </c:choose>
                                    </td>
                                    <td>
                                        <c:choose>
                                            <c:when test="${not empty submission.content}">
                                                <div style="max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"
                                                     title="${submission.content}">
                                                        ${submission.content}
                                                </div>
                                            </c:when>
                                            <c:otherwise>
                                                <span class="text-muted">暂无内容</span>
                                            </c:otherwise>
                                        </c:choose>
                                    </td>
                                    <td>
                                        <c:choose>
                                            <c:when test="${not empty submission.score}">
                                                <span class="badge bg-success">${submission.score} 分</span>
                                            </c:when>
                                            <c:otherwise>
                                                <span class="text-muted">暂无成绩</span>
                                            </c:otherwise>
                                        </c:choose>
                                    </td>
                                    <td>
                                        <c:choose>
                                            <c:when test="${not empty submission.createTimeStr}">
                                                <span class="badge bg-success">已提交</span>
                                            </c:when>
                                            <c:otherwise>
                                                <span class="badge bg-warning">未提交</span>
                                            </c:otherwise>
                                        </c:choose>
                                    </td>
                                    <td>
                                        <c:if test="${not empty submission.createTimeStr}">
                                            <button type="button" class="btn btn-sm btn-primary"
                                                    onclick="viewSubmission(${submission.id})">
                                                查看详情
                                            </button>
                                            <button type="button" class="btn btn-sm btn-warning"
                                                    onclick="scoreSubmission(${submission.id}, '${submission.student.user.realName}')">
                                                打分
                                            </button>
                                        </c:if>
                                    </td>
                                </tr>
                            </c:forEach>
                        </c:otherwise>
                    </c:choose>
                    </tbody>
                </table>
            </div>

            <!-- 分页 -->
            <c:if test="${totalPages > 1}">
                <nav aria-label="提交情况分页">
                    <ul class="pagination justify-content-center">
                        <c:if test="${currentPage > 1}">
                            <li class="page-item">
                                <a class="page-link" href="?page=${currentPage - 1}&status=${param.status}&studentName=${param.studentName}">上一页</a>
                            </li>
                        </c:if>

                        <c:forEach begin="1" end="${totalPages}" var="i">
                            <li class="page-item ${i == currentPage ? 'active' : ''}">
                                <a class="page-link" href="?page=${i}&status=${param.status}&studentName=${param.studentName}">${i}</a>
                            </li>
                        </c:forEach>

                        <c:if test="${currentPage < totalPages}">
                            <li class="page-item">
                                <a class="page-link" href="?page=${currentPage + 1}&status=${param.status}&studentName=${param.studentName}">下一页</a>
                            </li>
                        </c:if>
                    </ul>
                </nav>
            </c:if>
        </div>
    </div>
</div>

<!-- 作业提交详情模态框 -->
<div class="modal fade" id="submissionDetailModal" tabindex="-1" aria-labelledby="submissionDetailModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header bg-primary text-white">
                <h5 class="modal-title" id="submissionDetailModalLabel">
                    <i class="bi bi-file-text me-2"></i>作业提交详情
                </h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <div id="submissionDetailContent">
                    <div class="d-flex justify-content-center p-3">
                        <div class="spinner-border text-primary" role="status">
                            <span class="visually-hidden">加载中...</span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-warning" id="scoreSubmissionBtn" onclick="scoreSubmissionFromModal()">
                    <i class="bi bi-star me-1"></i>打分
                </button>
            </div>
        </div>
    </div>
</div>

<script src="${pageContext.request.contextPath}/resources/bootstrap5/js/bootstrap.bundle.min.js"></script>
<script>
    // 全局变量
    const contextPath = '${pageContext.request.contextPath}';

    // 页面加载完成后执行
    document.addEventListener('DOMContentLoaded', function() {
        // 用户名下拉菜单
        const userDropdownContainer = document.getElementById('userDropdownContainer');
        const userDropdown = document.getElementById('userDropdown');

        if (userDropdownContainer && userDropdown) {
            userDropdownContainer.addEventListener('click', function(e) {
                e.stopPropagation();
                userDropdown.classList.toggle('show');
            });

            document.addEventListener('click', function() {
                userDropdown.classList.remove('show');
            });
        }

        // 侧边栏菜单
        document.querySelectorAll('.has-submenu').forEach(function(item) {
            item.addEventListener('click', function(e) {
                e.preventDefault();
                this.parentNode.classList.toggle('open');
            });
        });
    });

    // 查看个人信息
    function showProfileModal() {
        // 关闭用户名下拉菜单
        const dropdown = document.getElementById('userDropdown');
        dropdown.classList.remove('show');

        // 弹出个人信息模态框
        alert('查看个人信息功能暂未实现');
    }

    // 查看提交详情
    let currentSubmissionId = null;
    let currentStudentName = null;

    function viewSubmission(submissionId) {
        currentSubmissionId = submissionId;

        // 显示模态框
        const modal = new bootstrap.Modal(document.getElementById('submissionDetailModal'));
        modal.show();

        // 显示加载动画
        document.getElementById('submissionDetailContent').innerHTML = `
                <div class="d-flex justify-content-center p-3">
                    <div class="spinner-border text-primary" role="status">
                        <span class="visually-hidden">加载中...</span>
                    </div>
                </div>
            `;

        // 发起AJAX请求获取详情数据
        fetch('${pageContext.request.contextPath}/teacher/homework/submission/detail/' + submissionId, {
            method: 'GET',
            headers: {
                'Accept': 'application/json',
            }
        })
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    const submission = data.submission;
                    currentStudentName = submission.student.user.realName;

                    // 构造HTML内容
                    let htmlContent = '<div class="row">';

                    // 学生信息
                    htmlContent += '<div class="col-md-6">';
                    htmlContent += '<div class="card border-0 shadow-sm mb-3">';
                    htmlContent += '<div class="card-header bg-light">';
                    htmlContent += '<h6 class="mb-0"><i class="bi bi-person me-2"></i>学生信息</h6>';
                    htmlContent += '</div>';
                    htmlContent += '<div class="card-body">';
                    htmlContent += '<p><strong>学号：</strong>' + (submission.student.user.username || '暂无') + '</p>';
                    htmlContent += '<p><strong>姓名：</strong>' + (submission.student.user.realName || '暂无') + '</p>';
                    htmlContent += '<p><strong>班级：</strong>' + (submission.student.clazz && submission.student.clazz.name ? submission.student.clazz.name : '暂无') + '</p>';
                    htmlContent += '</div>';
                    htmlContent += '</div>';
                    htmlContent += '</div>';

                    // 提交信息
                    htmlContent += '<div class="col-md-6">';
                    htmlContent += '<div class="card border-0 shadow-sm mb-3">';
                    htmlContent += '<div class="card-header bg-light">';
                    htmlContent += '<h6 class="mb-0"><i class="bi bi-clock me-2"></i>提交信息</h6>';
                    htmlContent += '</div>';
                    htmlContent += '<div class="card-body">';
                    htmlContent += '<p><strong>提交时间：</strong>' + (submission.createTimeStr || '暂无') + '</p>';
                    htmlContent += '<p><strong>提交状态：</strong>';
                    if (submission.createTimeStr) {
                        htmlContent += '<span class="badge bg-success">已提交</span>';
                    } else {
                        htmlContent += '<span class="badge bg-warning">未提交</span>';
                    }
                    htmlContent += '</p>';
                    htmlContent += '<p><strong>当前成绩：</strong>';
                    if (submission.score) {
                        htmlContent += '<span class="badge bg-success">' + submission.score + ' 分</span>';
                    } else {
                        htmlContent += '<span class="text-muted">暂无成绩</span>';
                    }
                    htmlContent += '</p>';
                    htmlContent += '</div>';
                    htmlContent += '</div>';
                    htmlContent += '</div>';
                    htmlContent += '</div>';

                    // 提交内容
                    htmlContent += '<div class="card border-0 shadow-sm">';
                    htmlContent += '<div class="card-header bg-light">';
                    htmlContent += '<h6 class="mb-0"><i class="bi bi-file-text me-2"></i>提交内容</h6>';
                    htmlContent += '</div>';
                    htmlContent += '<div class="card-body">';

                    // 文本内容
                    if (submission.content && submission.content.trim() !== '') {
                        htmlContent += '<div class="mb-3">';
                        htmlContent += '<h6 class="text-muted mb-2">文本内容：</h6>';
                        htmlContent += '<div class="bg-light p-3 rounded" style="max-height: 200px; overflow-y: auto;">';
                        htmlContent += submission.content;
                        htmlContent += '</div>';
                        htmlContent += '</div>';
                    }

                    // 附件下载
                    if (submission.fileUrl && submission.fileUrl.trim() !== '') {
                        htmlContent += '<div class="mb-3">';
                        htmlContent += '<h6 class="text-muted mb-2">附件下载：</h6>';
                        htmlContent += '<div class="d-flex align-items-center">';
                        htmlContent += '<i class="bi bi-download text-primary me-2"></i>';
                        htmlContent += '<a href="' + contextPath + '/' + submission.fileUrl + '" class="btn btn-sm btn-outline-primary" target="_blank" rel="noopener noreferrer">';
                        htmlContent += '<i class="bi bi-cloud-download me-1"></i>下载提交附件';
                        htmlContent += '</a>';
                        htmlContent += '</div>';
                        htmlContent += '</div>';
                    }

                    // 如果没有内容或附件
                    if ((!submission.content || submission.content.trim() === '') &&
                        (!submission.fileUrl || submission.fileUrl.trim() === '')) {
                        htmlContent += '<div class="bg-light p-3 rounded text-center">';
                        htmlContent += '<span class="text-muted">暂无提交内容</span>';
                        htmlContent += '</div>';
                    }

                    htmlContent += '</div>';
                    htmlContent += '</div>';

                    document.getElementById('submissionDetailContent').innerHTML = htmlContent;

                    // 根据提交状态显示打分按钮
                    const scoreBtn = document.getElementById('scoreSubmissionBtn');
                    if (submission.createTimeStr) {
                        scoreBtn.style.display = 'inline-block';
                    } else {
                        scoreBtn.style.display = 'none';
                    }
                } else {
                    document.getElementById('submissionDetailContent').innerHTML =
                        '<div class="alert alert-danger">' +
                        '<i class="bi bi-exclamation-triangle me-2"></i>' +
                        '获取提交详情失败：' + (data.message || '未知错误') +
                        '</div>';
                }
            })
            .catch(error => {
                console.error('Error:', error);
                document.getElementById('submissionDetailContent').innerHTML =
                    '<div class="alert alert-danger">' +
                    '<i class="bi bi-exclamation-triangle me-2"></i>' +
                    '服务器错误，请稍后再试' +
                    '</div>';
            });
    }

    // 从模态框中打分
    function scoreSubmissionFromModal() {
        if (!currentSubmissionId || !currentStudentName) {
            alert('未找到提交记录');
            return;
        }

        const score = prompt('请输入' + currentStudentName + ' 的分数（0-100）：');
        if (score !== null && score !== '') {
            const scoreNum = parseFloat(score);
            if (isNaN(scoreNum) || scoreNum < 0 || scoreNum > 100) {
                alert('请输入0-100之间的有效数字');
                return;
            }

            // 发起打分请求
            fetch('${pageContext.request.contextPath}/teacher/homework/submission/score', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                },
                body: 'submissionId=' + currentSubmissionId + '&score=' + scoreNum
            })
                .then(response => response.json())
                .then(data => {
                    if (data.success) {
                        alert('打分成功');
                        // 关闭模态框
                        const modal = bootstrap.Modal.getInstance(document.getElementById('submissionDetailModal'));
                        modal.hide();
                        // 刷新页面
                        location.reload();
                    } else {
                        alert('打分失败：' + (data.message || '未知错误'));
                    }
                })
                .catch(error => {
                    console.error('Error:', error);
                    alert('打分失败，请稍后再试');
                });
        }
    }

    // 打分
    function scoreSubmission(submissionId, studentName) {
        const score = prompt('请输入' + studentName + ' 的分数（0-100）：');
        if (score !== null && score !== '') {
            const scoreNum = parseFloat(score);
            if (isNaN(scoreNum) || scoreNum < 0 || scoreNum > 100) {
                alert('请输入0-100之间的有效数字');
                return;
            }

            // 发起打分请求
            fetch('${pageContext.request.contextPath}/teacher/homework/submission/score', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                },
                body: 'submissionId=' + submissionId + '&score=' + scoreNum
            })
                .then(response => response.json())
                .then(data => {
                    if (data.success) {
                        alert('打分成功');
                        location.reload();
                    } else {
                        alert('打分失败：' + (data.message || '未知错误'));
                    }
                })
                .catch(error => {
                    console.error('Error:', error);
                    alert('打分失败，请稍后再试');
                });
        }
    }
</script>
</body>
</html>

